<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends CI_Controller {

	public function __construct() {
		parent::__construct();

		if (!isset($_SESSION)) {
			session_start();
		}
		// $this->output->enable_profiler(true);

		$uid = $this->session->userdata('uid');
		$gid = $this->session->userdata('gid');
		if (!$uid) {
			redirect('admin/login');
		}

		$segs = $this->uri->segment_array();
		$segs = array_slice($segs, 0, 3);
		$segment_string = implode('/', $segs);

		$this->load->driver('cache');
		$cache_key = 'admin_gid_'.$gid;
		$rules = $this->cache->file->get($cache_key);
		if (empty($rules)) {
			$access = null;
			$this->load->model('auth_model', 'auth');
			$nodes = $this->auth->get_nodes();
			$g_access = $this->auth->get_access($gid);
			if ($g_access) {
				$access = explode(',', $g_access['rules']);
			}

			$rules = node_merge($nodes, $access);
			$this->cache->file->save($cache_key, $rules, 86400 * 30);
		}

		$this->_data['nodes'] = $rules;
		$this->_data['segment_string'] = $segment_string;
	}

}

/* End of file MY_Controller.php */
/* Location: ./application/core/MY_Controller.php */